Ext.extend(SHED.module, {
    init: function() {
        var menuWin = new SHED.Window({
            id: 'menuWin',
            title: '菜单详情',
            height: 305,
            items: new SHED.form.DWRForm({
                afterSubmit: function() {
                    tree.getRootNode().reload();
                },
                labelWidth: 85,
                baseParams: {
                    'action': 3
                },
                method: 'POST',
                dwr: {
                    load: smDwr.getMenuInfo,
                    save: smDwr.createMenu,
                    update: smDwr.updateMenu
                },
                items: [{
                    fieldLabel: '菜单编码',
                    name: 'menuID',
                    xtype: 'hidden'
                }, {
                    fieldLabel: '上级菜单编码',
                    name: 'menuUpID',
                    xtype: 'hidden'
                }, {
                    fieldLabel: '菜单名称',
                    name: 'menuName',
                    allowBlank: false
                }, {
                    fieldLabel: '菜单地址',
                    name: 'menuUrl',
                    value: '#',
                    allowBlank: false
                }, {
                    fieldLabel: '菜单序号',
                    name: 'menuSort',
                    xtype: 'numberfield',
                    allowDecimals: false,
                    allowNegative: false,
                    allowBlank: false
                }, {
                    store: [['1', '是'], ['0', '否']],
                    triggerAction: 'all',
                    mode: 'local',
                    editable: false,
                    fieldLabel: '是否叶子节点',
                    hiddenName: 'menuIsLeaf',
                    value: '0',
                    xtype: 'combo'
                }, {
                    store: [['1', '有效'], ['0', '无效']],
                    triggerAction: 'all',
                    mode: 'local',
                    editable: false,
                    fieldLabel: '状　　态',
                    hiddenName: 'menuState',
                    value: '1',
                    xtype: 'combo'
                }, {
                    fieldLabel: '菜单说明',
                    name: 'menuDesc',
                    xtype: 'textarea'
                }]
            })
        });
        
        var addBtn = new Ext.Toolbar.Button({
            text: '添加菜单',
            iconCls: 'btn_insert',
            handler: function(o, e) {
                var node = tree.getSelectionModel().getSelectedNode();
                if (node) {
                    menuWin.show();
                    menuWin.getBasicForm().setValues({
                        menuUpID: node.attributes.menuID
                    });
                } else {
                    SHED.msg('请选择上级菜单！');
                }
            }
        });
        
        var editBtn = new Ext.Toolbar.Button({
            text: '修改菜单',
            iconCls: 'btn_modify',
            handler: function(o, e) {
                var node = tree.getSelectionModel().getSelectedNode();
                if (node) {
                    if (node.isRoot) {
                        SHED.msg('不能修改根菜单！');
                    } else {
                        menuWin.load(node.attributes.menuID);
                    }
                } else {
                    SHED.msg('请选择要修改的菜单！');
                }
            }
        });
        
        var tree = new Ext.tree.TreePanel({
            useArrows: true,
            stateful: false,
            autoScroll: true,
            border: false,
            tbar: ['-', addBtn, editBtn],
            loader: new SHED.tree.DWRTreeLoader({
                dwrCall: smDwr.getMenu,
                nodeMeta: {
                    id: 'menuID',
                    text: 'menuName',
                    leaf: 'menuIsLeaf'
                },
                baseParams: {
                    action: 2
                },
                dataUrl: 'menuMan.do'
            }),
            root: {
                nodeType: 'async',
                text: '系统菜单',
                draggable: false,
                id: '0',
                menuID: '0',
                menuName: '系统菜单',
                leaf: false
            }
        });
        
        this.main.associatedComp = [menuWin];
        this.main.add(tree);
        this.main.doLayout();
    }
});
